package tr.edu.ozyegin.ccrg.raid.progressbar;

public class ProgressBar {
	private double totalPer = 0.0;
	private int last = -1;
	private long total = 0;
	public ProgressBar(long total){
		this.total = total;
	}
	public synchronized void updateProgress(long readed) {
		  
		//System.out.println(progressPercentage);
		totalPer += (double)readed/(double)this.total;
		if(((int)(totalPer*100))==last)return ;
		last= (int)(totalPer*100);
	    final int width = 50; // progress bar width in chars

	    System.out.print("\r[");
	    int i = 0;
	    for (; i <= (int)(totalPer*width); i++) {
	    	if(i == (int)(totalPer*width) && ((int)totalPer*100) != 100)System.out.print(">");
	    	else System.out.print("=");
	    }
	   	for (; i < width; i++) {
	   		System.out.print(" ");
	   	}
	   	System.out.print("] "+ ((int)(totalPer*100))+"%"+((((int)totalPer*100) != 100)?"":"\n"));
	}
}
